<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!-- import CSS -->
		<script src="../../js/commonCss.js"></script>
		<title>后台用户列表</title>
	</head>
	<body>
		<div id="app" v-cloak>
			<div class="pd10 border-bottom ft-14 h40">
				后台用户列表
				<el-button class="f-r" type="primary" icon="el-icon-plus" @click="addCont">添加后台用户</el-button>
			</div>
			<div class="pd10">		
				<el-form :inline="true" :model="formInline" class="demo-form-inline">
					<el-form-item>
						<el-input v-model="formInline.account" type="text" placeholder="账号"></el-input>
					</el-form-item>
					<el-form-item>
						<el-input v-model="formInline.name" type="text" placeholder="姓名"></el-input>
					</el-form-item>	
					<el-form-item>
						<el-select v-model="formInline.role" placeholder="角色">
							<el-option :label="item.label" :value="item.value" v-for="item in roleArr" :key="item.label"></el-option>
						</el-select>
					</el-form-item>
					<el-form-item>
						<el-button type="primary" @click="search">查询</el-button>
					</el-form-item>
				</el-form>
				<el-table :data="tableData" stripe border style="width: 100%">
					<el-table-column prop="account" label="考生账号"></el-table-column>
					<el-table-column prop="name" label="姓名"></el-table-column>
					<el-table-column prop="role" label="角色">
						<template slot-scope="scope">
							{{({"1":"省行","2":"市行","3":"行业协会","4":"运营人员"}[scope.row.role])}}
						</template>
					</el-table-column>
					<el-table-column prop="time" label="添加时间"></el-table-column>
					<el-table-column label="操作">
						<template slot-scope="scope">
							<el-button @click="handleEdit(scope.row)" type="text" size="medium">修改</el-button>
							<el-button @click="handleEdit(scope.row)" type="text" size="medium">停用</el-button>
						</template>
					</el-table-column>					
				</el-table>				
				<!-- 分页 -->
				<div class="bottomstate">
					<el-pagination class="f-r mt5" background @current-change="handleCurrentChange" :current-page="page" :page-size="limit" layout="total,prev, pager, next,jumper"
					 :total="total" ></el-pagination>
				</div>
			</div>
			<!-- 添加后台用户 -->
			<el-dialog :title="title" :visible.sync="dialogFormVisible">
				<el-form :model="form" label-width="120px">					
					<el-form-item label="账号:" >
						<el-input v-model="form.account" autocomplete="off" style="width:300px;"></el-input>
					</el-form-item>
					<el-form-item label="密码:" >
						<el-input show-password v-model="form.password" autocomplete="off" style="width:300px;"></el-input>
					</el-form-item>
					<el-form-item label="确认密码:" >
						<el-input show-password v-model="form.confirmpassword" autocomplete="off" style="width:300px;"></el-input>
					</el-form-item>
					<el-form-item label="角色:" >						
						<el-select v-model="form.role" placeholder="角色">
							<el-option :label="item.label" :value="item.value" v-for="item in roleArr" :key="item.label"></el-option>
						</el-select>
					</el-form-item>			
					<el-form-item label="姓名:" >
						<el-input v-model="form.name" autocomplete="off" style="width:300px;"></el-input>
					</el-form-item>
				</el-form>
				<div class="dialog-footer text-r">
					<el-button @click="dialogFormVisible = false">取 消</el-button>
					<el-button type="primary" @click="onSubmit">确 定</el-button>
				</div>
			</el-dialog>
		</div>
	</body>
	<script src="elementui-lib/lib/vue.js"></script>
	<script src="elementui-lib/lib/index.js"></script>
	<script src="js/jquery-1.9.1.min.js"></script>
	<script src="js/axios.js"></script>
	<script src="js/data.js"></script>
	<script>
		var app = new Vue({
			el: "#app",
			mixins: [mix],
			data: function() {
				return {
					formInline:{
						role:"",
						account:"",
						name:""
					},
					roleArr:[{
						value: '1',
						label: '省行'
					},{
						value: '2',
						label: '市行'
					},{
						value: '3',
						label: '行业协会'
					},{
						value: '4',
						label: '运营人员'
					}],
					tableData: [{
						account:"15133482706",
						name:"张三",
						role:"1",
						time:"2020年02月15日 13:26"
					},{
						account:"15133482706",
						name:"张三",
						role:"2",
						time:"2020年02月15日 13:26"
					}],	
					// 修改
					title:"",
					dialogFormVisible: false,
					form: {
						account:"",
						password:"",
						confirmpassword:"",
						role:"",
						name: ""
					},
				}
			},
			methods: {
				search:function(){
					console.log(this.formInline)
				},
				// 添加
				addCont:function(){
					this.title="添加后台用户"
					this.form.account=""
					this.form.password=""
					this.form.confirmpassword=""
					this.form.role=""
					this.form.name=""
					this.dialogFormVisible = true
				},
				handleEdit:function(row){
					this.title="修改后台用户"
					this.dialogFormVisible = true
				},
				// 确定
				IsNull: function() {
					let flag = false;
					if (this.form.account == "") {
						this.$message.error('账号不能为空');
						return flag = true;
					}
					if (this.form.password == "") {
						this.$message.error('密码不能为空');
						return flag = true;
					}
					if (this.form.confirmpassword == "") {
						this.$message.error('确认密码不能为空');
						return flag = true;
					}
					if (this.form.role == "") {
						this.$message.error('角色不能为空');
						return flag = true;
					}
					if (this.form.name == "") {
						this.$message.error('姓名不能为空');
						return flag = true;
					}
				},
				onSubmit:function(){
					let that = this;
					if (that.IsNull()) {
						return;
					}
					console.log('===',this.form)
					
					this.dialogFormVisible = false
				},
			},
			created() {
				
			},
		});
	</script>
</html>
